package com.ruoyi.WELD.controller;

import com.ruoyi.WELD.domain.DataRB;
import com.ruoyi.WELD.service.IDataRBService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/DataRB/dataRB")
public class DataRBController extends BaseController
{
    @Autowired
    private IDataRBService dataRBService;

    /*查询*/
    @GetMapping("/list")
    public TableDataInfo list(DataRB dataRB) {
        startPage();
        List<DataRB> list = dataRBService.selectDataRBList(dataRB);
        return getDataTable(list);
    }

    /*获取*/
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") Long ID)
    {
        return success(dataRBService.selectDataRBById(ID));
    }


    /*删除*/
    @DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable Long[] IDs)
    {
        return toAjax(dataRBService.deleteDataRBByIds(IDs));
    }

    /*清空数据*/
    @DeleteMapping("/clear")
    public AjaxResult clearAllDataRBing()
    {
        return toAjax(dataRBService.ClearDataRB());
    }

    /*导出*/
    @PostMapping("/export")
    public void export(Long[] ids,HttpServletResponse response)
    {
        List<DataRB> list = dataRBService.selectDataRBByIds(ids);
        ExcelUtil<DataRB> util = new ExcelUtil<DataRB>(DataRB.class);
        util.exportExcel(response, list, "数据");
    }

    /*导出全部，默认全选*/
    @PostMapping("/exportAll")
    public void exportAll(DataRB dataRB, HttpServletResponse response)
    {
        List<DataRB> list = dataRBService.selectDataRBList(dataRB);
        ExcelUtil<DataRB> util = new ExcelUtil<DataRB>(DataRB.class);
        util.exportExcel(response, list, "数据");
    }


}